package com.hongxun.modules.bss.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.bss.dao.DPictureDao;
import com.hongxun.modules.bss.entity.DPictureEntity;
import com.hongxun.modules.bss.service.DPictureService;



@Service("dPictureService")
public class DPictureServiceImpl implements DPictureService {
	@Autowired
	private DPictureDao dPictureDao;
	
	@Override
	public DPictureEntity queryObject(String guid){
		return dPictureDao.queryObject(guid);
	}
	
	@Override
	public List<DPictureEntity> queryList(Map<String, Object> map){
		return dPictureDao.queryList(map);
	}

	@Override
	public List<DPictureEntity> queryListForPlabel(Map<String, Object> map){
		return dPictureDao.queryListForPlabel(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return dPictureDao.queryTotal(map);
	}
	
	@Override
	public void save(DPictureEntity dPicture){
        if(dPicture.getGuid()==null||dPicture.getGuid().equals("")) {

		    dPicture.setGuid(UUID.randomUUID().toString());
        }
		dPictureDao.save(dPicture);
	}
	
	@Override
	public void update(DPictureEntity dPicture){
		dPictureDao.update(dPicture);
	}
	
	@Override
	public void delete(String guid){
		dPictureDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		dPictureDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<DPictureEntity> entities) {
		for (DPictureEntity d : entities) {
			if (d.getPDatastate().equals("删除")) {
				dPictureDao.delete(d.getGuid());
			} else {
				DPictureEntity dPictureEntity = dPictureDao.queryObject(d.getGuid());
				if (dPictureEntity == null) {
					dPictureDao.save(d);
				} else {
					dPictureDao.update(d);
				}
			}
		}
	}
}
